/*
 * Copyright 2012 Andrea Parodi
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package eban.storebyrules.filters;

import eban.storebyrules.filters.AbstractFilter;
import eban.storebyrules.filters.BinaryFilter;
import eban.storebyrules.filters.BooleanFilter;

/**
 * Author: parroit
 * Created: 25/05/12 23.51
 */
public class Filter {
    public static AbstractFilter Ne(String fieldName,Object operand){
        return new BinaryFilter(fieldName,BinaryFilter.FilterOperator.NotEqual,operand);
    }

    public static AbstractFilter eq(String fieldName, Object operand){
        return new BinaryFilter(fieldName,BinaryFilter.FilterOperator.Equal,operand);
    }

    public static AbstractFilter Gr(String fieldName,Object operand){
		return new BinaryFilter(fieldName,BinaryFilter.FilterOperator.Great,operand);
	}

    public static AbstractFilter Ls(String fieldName,Object operand){
		return new BinaryFilter(fieldName,BinaryFilter.FilterOperator.Less,operand);
	}

    public static AbstractFilter Ge(String fieldName,Object operand){
		return new BinaryFilter(fieldName,BinaryFilter.FilterOperator.GreatOrEqual,operand);
	}

    public static AbstractFilter Le(String fieldName,Object operand){
		return new BinaryFilter(fieldName,BinaryFilter.FilterOperator.LessOrEqual,operand);
	}

    public static AbstractFilter And(AbstractFilter left,AbstractFilter right){
		return new BooleanFilter(left,BooleanFilter.FilterOperator.And,right);
	}

    public static AbstractFilter Join(AbstractFilter... filters){
		AbstractFilter current=filters[0];
		for (int i=1;i<filters.length;i++)
			current=new BooleanFilter(current,BooleanFilter.FilterOperator.And,filters[i]);
		return current;
	}

    public static AbstractFilter Union(AbstractFilter... filters){
		AbstractFilter current=filters[0];
		for (int i=1;i<filters.length;i++)
			current=new BooleanFilter(current,BooleanFilter.FilterOperator.Or,filters[i]);
		return current;
	}

    public static AbstractFilter Or(AbstractFilter left,AbstractFilter right){
		return new BooleanFilter(left,BooleanFilter.FilterOperator.Or,right);
	}
}
